package edu.dayu.excel;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class xslTest implements ImportExcel<Map<Integer,String>>{
    private List<Map<Integer,String>> list = new ArrayList<>();

    private String str1;

    private String str2;

    public xslTest(){

    }

    public xslTest(String str1){
        this.str1 = str1;
    }

    /**
     *
     * @param str1 @ApiModelProperty
     * @param str2 @JsonFiled(name=   考虑有些参数不一样。
     */
    public xslTest(String str1,String str2){
        this.str1 = str1;
        this.str2 = str2;
    }

    @Override
    public void save(Map data) {
        list.add(data);
    }

    @Override
    public void from() {
        list.forEach(item->{
            String name = item.get(0);
            String up = toUp(name);
            String str = item.get(2);
            String remark = item.get(3);
            if (str.equals("string")){
                str = "String";
            }else if (str.equals("int")){
                str = "Integer";
            }else if (str.equals("long")){
                str = "Long";
            }else if(str.equals("object")){
                str = "Object";
            }else {
                str = "String";
            }
            System.out.println();
            if (str2!=null)
            System.out.println(str2+"\""+name+"\")");
            if (str1!=null)
            System.out.println(str1+"(\""+remark+"\")");
            System.out.println("private "+str+" "+up+";");
        });
    }

    private String toUp(String name){
        String[] s = name.split("_");
        StringBuffer str = new StringBuffer();
        str.append(s[0]);
        if (s.length>1){
            for (int i = 1; i < s.length; i++) {
                String s1 = s[i];
                str.append(s1.substring(0,1).toUpperCase()+s1.substring(1));
            }
        }
        return str.toString();
    }
}
